home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / util / misc / ReportPlus.lha / reportplus / source / f9.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-23  |  22.0 KB  |  638 lines

  1. #include <exec/types.h>
  2. #include <proto/exec.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <proto/intuition.h>
  6. #include <libraries/gadtools.h>
  7. #include <proto/gadtools.h>
  8. #include <libraries/resource.h>
  9. #include <proto/resource.h>
  10. #include <resources/battmem.h>
  11. #include <resources/battmembitsamiga.h>
  12. #include <resources/battmembitsshared.h>
  13. #include <proto/battmem.h>
  14. #include <graphics/gfx.h>
  15. #include <clib/graphics_protos.h>
  16. #include <dos/dos.h>
  17. #include <clib/dos_protos.h>
  18.  
  19. #include <ctype.h>
  20. #include <stdlib.h>
  21. #include "rp.h"
  22.  
  23. #define ALL_REACTION_CLASSES
  24. #include <reaction/reaction.h>
  25.  
  26. #define BOXWIDTH   (10 + (32 * 8))
  27. #define BOXHEIGHT  ( 6 + ( 3 * 8))
  28.  
  29. MODULE UBYTE IOBuffer[LONGESTFIELD + 1];
  30.  
  31. AGLOBAL struct Library*    BattMemBase = NULL;
  32.  
  33. // from rp.c
  34. IMPORT ABOOL               BattBuffer[96];
  35. IMPORT SBYTE               page;
  36. IMPORT struct Menu*        MenuPtr;
  37. IMPORT struct TextFont*    FontPtr;
  38. IMPORT struct Screen*      ScreenPtr;
  39. IMPORT struct Window*      MainWindowPtr;
  40. IMPORT TEXT                aslresult[PATHNAMEFIELD + 1];
  41. IMPORT Object*             WinObject[FUNCTIONS + 1];
  42.  
  43. AGLOBAL struct Gadget*     batt_gadgets[GIDS_9 + 1];
  44.  
  45. MODULE struct
  46. {   TEXT output[PATHNAMEFIELD + 1];
  47. } batt =
  48. {   ""
  49. };
  50.  
  51. MODULE void updatebattgadgets(void);
  52. MODULE void drawbit(ULONG bit, UBYTE colour);
  53. MODULE void readbatt(ABOOL print);
  54.  
  55. AGLOBAL void batt1(void)
  56. {   ULONG       hostid = 0;
  57.     struct Hook Hook9Struct;
  58.  
  59.     if (!BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR])
  60.     {   hostid += 4;
  61.     }
  62.     if (!BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR + 1])
  63.     {   hostid += 2;
  64.     }
  65.     if (!BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR + 2])
  66.     {   hostid++;
  67.     }
  68.  
  69.     if (!BattMemBase)
  70.     {   if (!(BattMemBase = OpenResource(BATTMEMNAME)))
  71.         {   rq("Can't open battery RAM resource!");
  72.     }   }
  73.  
  74.     InitHook(&Hook9Struct, Hook9Func, NULL);
  75.  
  76.     /* Create the window object. */
  77.     lockscreen();
  78.  
  79.     if (!(WinObject[9] =
  80.     NewObject
  81.     (
  82.     WINDOW_GetClass(), NULL,
  83.     WA_PubScreen,                 ScreenPtr,
  84.     WA_ScreenTitle,               "Report+",
  85.     WA_Title,                     "Report+: Battery-backed Memory Editor",
  86.     WA_Activate,                  TRUE,
  87.     WA_DepthGadget,               TRUE,
  88.     WA_DragBar,                   TRUE,
  89.     WA_CloseGadget,               TRUE,
  90.     WA_IDCMP,                     IDCMP_RAWKEY | IDCMP_MOUSEBUTTONS,
  91.     WINDOW_IDCMPHook,             &Hook9Struct,
  92.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY | IDCMP_MOUSEBUTTONS,
  93.     WINDOW_MenuStrip,             MenuPtr,
  94.     WINDOW_Position,              WPOS_CENTERSCREEN,
  95.     WINDOW_ParentGroup,           batt_gadgets[GID_9_LY1] =
  96.                                   NewObject(LAYOUT_GetClass(), NULL,
  97.         // root-layout
  98.         LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  99.         LAYOUT_SpaceOuter,        TRUE,
  100.         LAYOUT_DeferLayout,       TRUE,
  101.         LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  102.             // layout
  103.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  104.             LAYOUT_SpaceOuter,    TRUE,
  105.             LAYOUT_VertAlignment, LALIGN_CENTER,
  106.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  107.             LAYOUT_BevelStyle,    BVS_NONE,
  108.                 LAYOUT_AddChild,
  109.                 NewObject
  110.                 (   LAYOUT_GetClass(),    NULL,
  111.                     LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  112.                     LAYOUT_SpaceOuter,    TRUE,
  113.                     LAYOUT_VertAlignment, LALIGN_CENTER,
  114.                     LAYOUT_HorizAlignment,LALIGN_LEFT,
  115.                     LAYOUT_BevelStyle,    BVS_FIELD,
  116.                     LAYOUT_AddChild,          batt_gadgets[GID_9_CB1] =
  117.                     NewObject
  118.                     (   CHECKBOX_GetClass(),  NULL,
  119.                         GA_ID,                GID_9_CB1,
  120.                         GA_RelVerify,         TRUE,
  121.                         GA_Text,              "AMIGA AMNESIA ($00)",
  122.                         GA_Selected,          (BOOL) ((BattBuffer[BATTMEM_AMIGA_AMNESIA_ADDR] & 1)? 0 : 1),
  123.                     TAG_END),
  124.                     CHILD_WeightedHeight,     0,
  125.                     LAYOUT_AddChild,          batt_gadgets[GID_9_CB2] =
  126.                     NewObject
  127.                     (   CHECKBOX_GetClass(),  NULL,
  128.                         GA_ID,                GID_9_CB2,
  129.                         GA_RelVerify,         TRUE,
  130.                         GA_Text,              "SHARED AMNESIA ($40)",
  131.                         GA_Selected,          (BOOL) ((BattBuffer[BATTMEM_SHARED_AMNESIA_ADDR] & 1)? 0 : 1),
  132.                     TAG_END),
  133.                     CHILD_WeightedHeight,     0,
  134.                     LAYOUT_AddChild,          batt_gadgets[GID_9_CB3] =
  135.                     NewObject
  136.                     (   CHECKBOX_GetClass(),  NULL,
  137.                         GA_ID,                GID_9_CB3,
  138.                         GA_RelVerify,         TRUE,
  139.                         GA_Text,              "SCSI TIMEOUT ($01)",
  140.                         GA_Selected,          (BOOL) BattBuffer[BATTMEM_SCSI_TIMEOUT_ADDR],
  141.                     TAG_END),
  142.                     CHILD_WeightedHeight,     0,
  143.                     LAYOUT_AddChild,          batt_gadgets[GID_9_CB4] =
  144.                     NewObject
  145.                     (   CHECKBOX_GetClass(),  NULL,
  146.                         GA_ID,                GID_9_CB4,
  147.                         GA_RelVerify,         TRUE,
  148.                         GA_Text,              "SCSI LUNS ($02)",
  149.                         GA_Selected,          (BOOL) BattBuffer[BATTMEM_SCSI_LUNS_ADDR],
  150.                     TAG_END),
  151.                     CHILD_WeightedHeight,     0,
  152.                     LAYOUT_AddChild,          batt_gadgets[GID_9_CB5] =
  153.                     NewObject
  154.                     (   CHECKBOX_GetClass(),  NULL,
  155.                         GA_ID,                GID_9_CB5,
  156.                         GA_RelVerify,         TRUE,
  157.                         GA_Text,              "SCSI SYNC XFER ($44)",
  158.                         GA_Selected,          (BOOL) BattBuffer[BATTMEM_SCSI_SYNC_XFER_ADDR],
  159.                     TAG_END),
  160.                     CHILD_WeightedHeight,     0,
  161.                     LAYOUT_AddChild,          batt_gadgets[GID_9_CB6] =
  162.                     NewObject
  163.                     (   CHECKBOX_GetClass(),  NULL,
  164.                         GA_ID,                GID_9_CB6,
  165.                         GA_RelVerify,         TRUE,
  166.                         GA_Text,              "SCSI FAST SYNC ($45)",
  167.                         GA_Selected,          (BOOL) ((BattBuffer[BATTMEM_SCSI_FAST_SYNC_ADDR] & 1)? 0 : 1),
  168.  
  169.                     TAG_END),
  170.                     CHILD_WeightedHeight,     0,
  171.                     LAYOUT_AddChild,          batt_gadgets[GID_9_CB7] =
  172.                     NewObject
  173.                     (   CHECKBOX_GetClass(),  NULL,
  174.                         GA_ID,                GID_9_CB7,
  175.                         GA_RelVerify,         TRUE,
  176.                         GA_Text,              "SCSI TAG QUEUES ($46)",
  177.                         GA_Selected,          (BOOL) BattBuffer[BATTMEM_SCSI_TAG_QUEUES_ADDR],
  178.                     TAG_END),
  179.                     CHILD_WeightedHeight,     0,
  180.                     LAYOUT_AddChild,
  181.                     NewObject
  182.                     (   LAYOUT_GetClass(),    NULL,
  183.                         LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  184.                         LAYOUT_SpaceOuter,    TRUE,
  185.                         LAYOUT_VertAlignment, LALIGN_CENTER,
  186.                         LAYOUT_HorizAlignment,LALIGN_LEFT,
  187.                         LAYOUT_BevelStyle,    BVS_NONE,
  188.                         LAYOUT_AddImage,
  189.                         NewObject
  190.                         (   LABEL_GetClass(), NULL,
  191.                             LABEL_Text,       "SCSI HOST ID ($41-43):",
  192.                         TAG_END),
  193.                         CHILD_WeightedWidth,  0,
  194.                         LAYOUT_AddChild,          batt_gadgets[GID_9_IN1] =
  195.                         NewObject
  196.                         (   INTEGER_GetClass(),   NULL,
  197.                             GA_ID,                GID_9_IN1,
  198.                             GA_RelVerify,         TRUE,
  199.                             GA_TabCycle,          TRUE,
  200.                             INTEGER_Number,       hostid,
  201.                             INTEGER_Minimum,      0,
  202.                             INTEGER_Maximum,      7,
  203.                             INTEGER_MinVisible,   1,
  204.                         TAG_END),                                      
  205.                         CHILD_WeightedHeight,     0,
  206.                     TAG_END),
  207.                     CHILD_WeightedHeight,         0,
  208.             TAG_END),
  209.             CHILD_WeightedWidth,      0,
  210.                 LAYOUT_AddChild,
  211.                 NewObject
  212.                 (   LAYOUT_GetClass(),    NULL,
  213.                     LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  214.                     LAYOUT_SpaceOuter,    TRUE,
  215.                     LAYOUT_VertAlignment, LALIGN_CENTER,
  216.                     LAYOUT_HorizAlignment,LALIGN_CENTER,
  217.                     LAYOUT_BevelStyle,    BVS_FIELD,
  218.                     LAYOUT_AddChild,      batt_gadgets[GID_9_SP1] =
  219.                     NewObject
  220.                     (   SPACE_GetClass(), NULL,
  221.                         GA_ID,            GID_9_SP1,
  222.                         GA_RelVerify,     TRUE,
  223.                         SPACE_MinWidth,   BOXWIDTH,
  224.                         SPACE_MinHeight,  BOXHEIGHT,
  225.                         SPACE_BevelStyle, BVS_FIELD,
  226.                     TAG_END),
  227.                     CHILD_WeightedHeight, 0,
  228.                     LAYOUT_AddChild,
  229.                     NewObject
  230.                     (   LAYOUT_GetClass(),    NULL,
  231.                         LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  232.                         LAYOUT_SpaceOuter,    TRUE,
  233.                         LAYOUT_VertAlignment, LALIGN_CENTER,
  234.                         LAYOUT_HorizAlignment,LALIGN_CENTER,
  235.                         LAYOUT_BevelStyle,    BVS_NONE,
  236.                         LAYOUT_AddChild,      batt_gadgets[GID_9_BU1] =
  237.                         NewObject
  238.                         (   NULL,             "button.gadget",
  239.                             GA_ID,            GID_9_BU1,
  240.                             GA_RelVerify,     TRUE,
  241.                             GA_Text,          "_Revert",
  242.                         TAG_END),
  243.                         CHILD_WeightedWidth,  50,
  244.                         LAYOUT_AddChild,      batt_gadgets[GID_9_BU2] =
  245.                         NewObject
  246.                         (   NULL,             "button.gadget",
  247.                             GA_ID,            GID_9_BU2,
  248.                             GA_RelVerify,     TRUE,
  249.                             GA_Text,          "_Write",
  250.                         TAG_END),
  251.                         CHILD_WeightedWidth,  50,
  252.                     TAG_END),
  253.                     CHILD_WeightedHeight,     0,
  254.             TAG_END),
  255.             CHILD_WeightedHeight,         0,
  256.         TAG_END),
  257.         CHILD_WeightedHeight,         0,
  258.     TAG_END),
  259.     TAG_END
  260.     )))
  261.     {   rq("Can't create ReAction object(s)!");
  262.     }
  263.     unlockscreen();
  264.     openwindow();
  265.     ActivateLayoutGadget(batt_gadgets[GID_9_LY1], MainWindowPtr, NULL, (Object) batt_gadgets[GID_9_IN1]);
  266.  
  267.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_OPEN,   NOSUB));
  268.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVE,   NOSUB));
  269.     OnMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVEAS, NOSUB));
  270.  
  271.     SetFont(MainWindowPtr->RPort, FontPtr);
  272.  
  273.     readbatt(TRUE);
  274.  
  275.     loop();
  276.     closewindow();
  277. }
  278.  
  279. MODULE void updatebattgadgets(void)
  280. {   ULONG hostid = 0;
  281.  
  282.     SetGadgetAttrs
  283.     (   batt_gadgets[GID_9_CB1], MainWindowPtr, NULL,
  284.         GA_Selected, (BOOL) ((BattBuffer[BATTMEM_AMIGA_AMNESIA_ADDR] & 1)? 0 : 1),
  285.     TAG_END);
  286.     RefreshGadgets((struct Gadget *) batt_gadgets[GID_9_CB1], MainWindowPtr, NULL);
  287.  
  288.     SetGadgetAttrs
  289.     (   batt_gadgets[GID_9_CB2], MainWindowPtr, NULL,
  290.         GA_Selected, (BOOL) ((BattBuffer[BATTMEM_SHARED_AMNESIA_ADDR] & 1)? 0 : 1),
  291.     TAG_END);
  292.     RefreshGadgets((struct Gadget *) batt_gadgets[GID_9_CB2], MainWindowPtr, NULL);
  293.  
  294.     SetGadgetAttrs
  295.     (   batt_gadgets[GID_9_CB3], MainWindowPtr, NULL,
  296.         GA_Selected, (BOOL) BattBuffer[BATTMEM_SCSI_TIMEOUT_ADDR],
  297.     TAG_END);
  298.     RefreshGadgets((struct Gadget *) batt_gadgets[GID_9_CB3], MainWindowPtr, NULL);
  299.  
  300.     SetGadgetAttrs
  301.     (   batt_gadgets[GID_9_CB4], MainWindowPtr, NULL,
  302.         GA_Selected, (BOOL) BattBuffer[BATTMEM_SCSI_LUNS_ADDR],
  303.     TAG_END);
  304.     RefreshGadgets((struct Gadget *) batt_gadgets[GID_9_CB4], MainWindowPtr, NULL);
  305.  
  306.     SetGadgetAttrs
  307.     (   batt_gadgets[GID_9_CB5], MainWindowPtr, NULL,
  308.         GA_Selected, (BOOL) BattBuffer[BATTMEM_SCSI_SYNC_XFER_ADDR],
  309.     TAG_END);
  310.     RefreshGadgets((struct Gadget *) batt_gadgets[GID_9_CB5], MainWindowPtr, NULL);
  311.  
  312.     SetGadgetAttrs
  313.     (   batt_gadgets[GID_9_CB6], MainWindowPtr, NULL,
  314.         GA_Selected, (BOOL) ((BattBuffer[BATTMEM_SCSI_FAST_SYNC_ADDR] & 1)? 0 : 1),
  315.     TAG_END);
  316.     RefreshGadgets((struct Gadget *) batt_gadgets[GID_9_CB6], MainWindowPtr, NULL);
  317.  
  318.     SetGadgetAttrs
  319.     (   batt_gadgets[GID_9_CB7], MainWindowPtr, NULL,
  320.         GA_Selected, (BOOL) BattBuffer[BATTMEM_SCSI_TAG_QUEUES_ADDR],
  321.     TAG_END);
  322.     RefreshGadgets((struct Gadget *) batt_gadgets[GID_9_CB7], MainWindowPtr, NULL);
  323.  
  324.     if (!BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR])
  325.     {   hostid += 4;
  326.     }
  327.     if (!BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR + 1])
  328.     {   hostid += 2;
  329.     }
  330.     if (!BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR + 2])
  331.     {   hostid++;
  332.     }
  333.  
  334.     SetGadgetAttrs
  335.     (   batt_gadgets[GID_9_IN1], MainWindowPtr, NULL,
  336.         INTEGER_Number, hostid,
  337.     TAG_END);
  338. }
  339.  
  340. MODULE void drawbit(ULONG bit, UBYTE colour)
  341. {   Move
  342.     (   MainWindowPtr->RPort,
  343.         batt_gadgets[GID_9_SP1]->LeftEdge + 5 +         (8 * (bit % 32)),
  344.         batt_gadgets[GID_9_SP1]->TopEdge  + 2 + FONTY + (8 * (bit / 32))
  345.     );
  346.  
  347.     if
  348.     (   (bit >= 0x0  && bit <= 0x2)
  349.      || (bit >= 0x40 && bit <= 0x46)
  350.     )
  351.     {   if (colour == BLACK)
  352.         {   colour = GREY;
  353.         }
  354.         SetAPen(MainWindowPtr->RPort, colour);
  355.         SetBPen(MainWindowPtr->RPort, BLACK);
  356.     } else
  357.     {   SetAPen(MainWindowPtr->RPort, colour);
  358.         SetBPen(MainWindowPtr->RPort, GREY);
  359.     }
  360.  
  361.     if (BattBuffer[bit] & 1)
  362.         Text(MainWindowPtr->RPort, "1", 1);
  363.     else
  364.         Text(MainWindowPtr->RPort, "0", 1);
  365.     return;
  366. }
  367.  
  368. MODULE void readbatt(ABOOL print)
  369. {   ULONG i;
  370.  
  371.     ObtainBattSemaphore();
  372.     for (i = 0; i <= 95; i++)
  373.     {   if (ReadBattMem(&BattBuffer[i], i, 1))
  374.         {   ReleaseBattSemaphore();
  375.             rq("Can't read battery-backed memory!");
  376.     }   }
  377.     if (print)
  378.         for (i = 0; i <= 95; i++)
  379.             drawbit(i, BLACK);
  380.     ReleaseBattSemaphore();
  381. }
  382.  
  383. AGLOBAL void batt_loop(ULONG gid)
  384. {   ULONG thisbit, hostid;
  385.  
  386.     switch(gid)
  387.     {
  388.     case GID_9_BU1:
  389.         readbatt(TRUE);
  390.         updatebattgadgets();
  391.     break;
  392.     case GID_9_BU2:
  393.         writebatt(TRUE);
  394.     break;
  395.     case GID_9_IN1:
  396.         if (!(GetAttr
  397.         (   INTEGER_Number, batt_gadgets[GID_9_IN1], (ULONG *) &hostid
  398.         )))
  399.         {   rq("Unsupported inquiry!"); // should never happen
  400.         }
  401.         if (hostid < 0 || hostid > 7)
  402.         {   hostid = 7;
  403.         }
  404.         SetGadgetAttrs
  405.         (   batt_gadgets[GID_9_IN1], MainWindowPtr, NULL,
  406.             INTEGER_Number, hostid,
  407.             TAG_END
  408.         );
  409.         BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR]     = (hostid & 4)? 0 : 1;
  410.         BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR + 1] = (hostid & 2)? 0 : 1;
  411.         BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR + 2] = (hostid & 1)? 0 : 1;
  412.         drawbit(BATTMEM_SCSI_HOST_ID_ADDR    , WHITE);
  413.         drawbit(BATTMEM_SCSI_HOST_ID_ADDR + 1, WHITE);
  414.         drawbit(BATTMEM_SCSI_HOST_ID_ADDR + 2, WHITE);
  415.     break;
  416.     case GID_9_CB1:
  417.         if (!(GetAttr
  418.         (   GA_Selected, batt_gadgets[GID_9_CB1], (ULONG *) &thisbit
  419.         )))
  420.         {   rq("Unsupported inquiry!"); // should never happen
  421.         }
  422.         if (thisbit)
  423.         {   BattBuffer[BATTMEM_AMIGA_AMNESIA_ADDR] = 0;
  424.         } else
  425.         {   BattBuffer[BATTMEM_AMIGA_AMNESIA_ADDR] = 1;
  426.         }
  427.         drawbit(BATTMEM_AMIGA_AMNESIA_ADDR, WHITE);
  428.     break;
  429.     case GID_9_CB2:
  430.         if (!(GetAttr
  431.         (   GA_Selected, batt_gadgets[GID_9_CB2], (ULONG *) &thisbit
  432.         )))
  433.         {   rq("Unsupported inquiry!"); // should never happen
  434.         }
  435.         if (thisbit)
  436.         {   BattBuffer[BATTMEM_SHARED_AMNESIA_ADDR] = 0;
  437.         } else
  438.         {   BattBuffer[BATTMEM_SHARED_AMNESIA_ADDR] = 1;
  439.         }
  440.         drawbit(BATTMEM_SHARED_AMNESIA_ADDR, WHITE);
  441.     break;
  442.     case GID_9_CB3:
  443.         if (!(GetAttr
  444.         (   GA_Selected, batt_gadgets[GID_9_CB3], (ULONG *) &thisbit
  445.         )))
  446.         {   rq("Unsupported inquiry!"); // should never happen
  447.         }
  448.         if (thisbit)
  449.         {   BattBuffer[BATTMEM_SCSI_TIMEOUT_ADDR] = 1;
  450.         } else
  451.         {   BattBuffer[BATTMEM_SCSI_TIMEOUT_ADDR] = 0;
  452.         }
  453.         drawbit(BATTMEM_SCSI_TIMEOUT_ADDR, WHITE);
  454.     break;
  455.     case GID_9_CB4:
  456.         if (!(GetAttr
  457.         (   GA_Selected, batt_gadgets[GID_9_CB4], (ULONG *) &thisbit
  458.         )))
  459.         {   rq("Unsupported inquiry!"); // should never happen
  460.         }
  461.         if (thisbit)
  462.         {   BattBuffer[BATTMEM_SCSI_LUNS_ADDR] = 1;
  463.         } else
  464.         {   BattBuffer[BATTMEM_SCSI_LUNS_ADDR] = 0;
  465.         }
  466.         drawbit(BATTMEM_SCSI_LUNS_ADDR, WHITE);
  467.     break;
  468.     case GID_9_CB5:
  469.         if (!(GetAttr
  470.         (   GA_Selected, batt_gadgets[GID_9_CB5], (ULONG *) &thisbit
  471.         )))
  472.         {   rq("Unsupported inquiry!"); // should never happen
  473.         }
  474.         if (thisbit)
  475.         {   BattBuffer[BATTMEM_SCSI_SYNC_XFER_ADDR] = 1;
  476.         } else
  477.         {   BattBuffer[BATTMEM_SCSI_SYNC_XFER_ADDR] = 0;
  478.         }
  479.         drawbit(BATTMEM_SCSI_SYNC_XFER_ADDR, WHITE);
  480.     break;
  481.     case GID_9_CB6:
  482.         if (!(GetAttr
  483.         (   GA_Selected, batt_gadgets[GID_9_CB6], (ULONG *) &thisbit
  484.         )))
  485.         {   rq("Unsupported inquiry!"); // should never happen
  486.         }
  487.         if (thisbit)
  488.         {   BattBuffer[BATTMEM_SCSI_FAST_SYNC_ADDR] = 0;
  489.         } else
  490.         {   BattBuffer[BATTMEM_SCSI_FAST_SYNC_ADDR] = 1;
  491.         }
  492.         drawbit(BATTMEM_SCSI_FAST_SYNC_ADDR, WHITE);
  493.     break;
  494.     case GID_9_CB7:
  495.         if (!(GetAttr
  496.         (   GA_Selected, batt_gadgets[GID_9_CB7], (ULONG *) &thisbit
  497.         )))
  498.         {   rq("Unsupported inquiry!"); // should never happen
  499.         }
  500.         if (thisbit)
  501.         {   BattBuffer[BATTMEM_SCSI_TAG_QUEUES_ADDR] = 1;
  502.         } else
  503.         {   BattBuffer[BATTMEM_SCSI_TAG_QUEUES_ADDR] = 0;
  504.         }
  505.         drawbit(BATTMEM_SCSI_TAG_QUEUES_ADDR, WHITE);
  506.     break;
  507.     default:
  508.     break;
  509. }   }
  510.  
  511. AGLOBAL void writebatt(ABOOL verify)
  512. {   ULONG i;
  513.  
  514.     ObtainBattSemaphore();
  515.     for (i = 0; i <= 95; i++)
  516.     {   if (WriteBattMem(&BattBuffer[i], i, 1))
  517.         {   ReleaseBattSemaphore();
  518.             rq("Can't write battery-backed memory!");
  519.     }   }
  520.     ReleaseBattSemaphore();
  521.     if (verify)
  522.     {   readbatt(TRUE);
  523. }   }
  524.  
  525. AGLOBAL void batt_open(void)
  526. {   BPTR  FileHandle;
  527.     ULONG i;
  528.  
  529.     if (asl("~(#?.info)"))
  530.     {   if (!(FileHandle = (BPTR) Open(aslresult, MODE_OLDFILE)))
  531.         {   DisplayBeep(NULL);
  532.             return;
  533.         }
  534.         /* The format of "battery RAM" files (suggested extension
  535.           ".battery") is simply a raw dump of the 12 bytes. */
  536.  
  537.         if (Read(FileHandle, IOBuffer, 12) == -1)
  538.         {   DisplayBeep(NULL);
  539.         } else
  540.         {   for (i = 0; i <= 95; i++)
  541.             {   if (IOBuffer[i / 8] & (1 << (i % 8)))
  542.                 {   BattBuffer[i] = TRUE;
  543.                 } else BattBuffer[i] = FALSE;
  544.                 drawbit(i, WHITE);
  545.         }   }
  546.         Close(FileHandle);
  547.     }
  548.     updatebattgadgets();
  549. }
  550.  
  551. AGLOBAL void batt_save(ABOOL saveas)
  552. {   BPTR  FileHandle;
  553.     ULONG i;
  554.  
  555.     if (!batt.output[0] || saveas) // if we need a filename
  556.     {   if (saveasl("Save Battery RAM", "~(#?.info)"))
  557.         {   strcpy(batt.output, aslresult);
  558.         } else return;
  559.     }
  560.  
  561.     if (!(FileHandle = (BPTR) Open(aslresult, MODE_NEWFILE)))
  562.     {   DisplayBeep(NULL);
  563.         return;
  564.     }
  565.     for (i = 0; i <= 11; i++)
  566.     {   IOBuffer[i] = 0;
  567.     }
  568.     for (i = 0; i <= 95; i++)
  569.     {   if (BattBuffer[i])
  570.         {   IOBuffer[i / 8] |= BattBuffer[i] << (i % 8);
  571.     }   }
  572.     if (Write(FileHandle, IOBuffer, 12) == -1)
  573.     {   DisplayBeep(NULL);
  574.     }
  575.     Close(FileHandle);
  576. }
  577.  
  578. AGLOBAL ULONG Hook9Func(struct Hook *h, VOID *o, VOID *msg)
  579. {   /* "When the hook is called, the data argument points to the 
  580.     window object and message argument to the IntuiMessage." */
  581.  
  582.     AUTO    ULONG class;
  583.     AUTO    UWORD code, qual;
  584.     AUTO    SWORD mousex, mousey, realx, realy, bit;
  585.     PERSIST ULONG count = 0;
  586.  
  587.     geta4(); // wait till here before doing anything
  588.  
  589.      class = ((struct IntuiMessage *) msg)->Class;
  590.       code = ((struct IntuiMessage *) msg)->Code;
  591.       qual = ((struct IntuiMessage *) msg)->Qualifier;
  592.     mousex = ((struct IntuiMessage *) msg)->MouseX;
  593.     mousey = ((struct IntuiMessage *) msg)->MouseY;
  594.  
  595.     if (class == IDCMP_RAWKEY)
  596.     {   switch(code)
  597.         {
  598.         case SCAN_HELP:
  599.             helpabout();
  600.         break;
  601.         case SCAN_ESCAPE:
  602.             if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  603.             {   cleanexit(EXIT_SUCCESS);
  604.             } else page = 0;
  605.         break;
  606.         default:
  607.         break;
  608.     }   }
  609.     else
  610.     {   assert(class == IDCMP_MOUSEBUTTONS);
  611.  
  612.         if
  613.         (   mousex >= batt_gadgets[GID_9_SP1]->LeftEdge
  614.          && mousex <= batt_gadgets[GID_9_SP1]->LeftEdge + batt_gadgets[GID_9_SP1]->Width
  615.          && mousey >= batt_gadgets[GID_9_SP1]->TopEdge
  616.          && mousey <= batt_gadgets[GID_9_SP1]->TopEdge  + batt_gadgets[GID_9_SP1]->Height
  617.         )
  618.         {   realx = (mousex - batt_gadgets[GID_9_SP1]->LeftEdge - 5) / 8;
  619.             realy = (mousey - batt_gadgets[GID_9_SP1]->TopEdge  - 4) / 8;
  620.             if (realx < 0)
  621.                 realx = 0;
  622.             elif (realx > 31)
  623.                 realx = 31;
  624.             if (realy < 0)
  625.                 realy = 0;
  626.             elif (realy > 2)
  627.                 realy = 2;
  628.             bit = (realy * 32) + realx;
  629.             if (!(count % 2))
  630.             {   BattBuffer[bit] ^= 1;
  631.                 drawbit(bit, WHITE);
  632.                 updatebattgadgets();
  633.             }
  634.             count++;
  635.     }   }
  636.     return(1);
  637. }
  638.